package Sort;

import java.util.Arrays;

public class _274_H_Index {
    public int hIndex(int[] citations) {
        if(citations.length==0) return 0;
        if (citations.length == 1) {
            if (citations[0] == 0) {
                return 0;
            } else {
                return 1;
            }
        }
        int res = 0;
        int len = citations.length;
        Arrays.sort(citations);
        for (int i = 1; i <= len; i++) {
            if (citations[len - i] >= i) {
                res = i;
            } else {
                break;
            }
        }
        return res;
    }
}
